#!/usr/bin/python3
# _*_ coding: utf-8 _*_
#
# Copyright (C) 2024 - 2024 heihieyouheihei, Inc. All Rights Reserved 
#
# @Time    : 2024/9/20 20:22
# @Author  : Yuyun
# @File    : 删除链表重复元素.py
# @IDE     : PyCharm

class ListNode:
    def __init__(self, val=0, next=None):
        self.val = val
        self.next = next
class LinkList:
    def __init__(self, nums):
        self.dummy_head = ListNode()
        self.size = len(nums)
        cur = self.dummy_head
        for num in nums:
            tmp = ListNode(num)
            cur.next = tmp
            cur = cur.next
    def show_linklist(self):
        cur = self.dummy_head.next
        while cur:
            print(cur.val, end=' ')
            cur = cur.next
        print()
    def delete_repeat(self):
        cur = self.dummy_head.next
        while cur != None:
            #   链表末尾，直接退出，不再判断；
            #   否则会因为链表越界报错NoneType 无 val，即cur.next = None时，无val值，导致程序异常退出
            if cur.next == None:
                break
            if cur.val == cur.next.val:
                cur.next = cur.next.next
            else:
                cur = cur.next

if __name__ == '__main__':
    while True:
        try:
            n, *num = list(map(int, input().split()))
            if n == 0:
                print("list is empty")
                #   此处必须用break，
                #   本人一开始用continue，一直报错“潜在的数组或指针越界，请检查代码。”，找了好久原因
                break
            head = LinkList(num)
            head.show_linklist()
            head.delete_repeat()
            head.show_linklist()
        except:
            #   此处必须为break，换成打印异常输出的写法，结果会报错“输出超限”，找了半天原因
            break